<?php
/**
 * Created by PhpStorm.
 * User: alice
 * Date: 2015/12/28
 * Time: 14:46
 */

class Involved_HarbourModel extends BaseModel
{
    protected $table = 'harbour';

    /*********************   APP接口    *********************/

    /**
     * 港口详情
     * @param $harbour_id
     * @return array
     * @throws Exception
     * @author alice
     * @date 2016-1-19
     */
    public function GetHarbourDetail($harbour_id)
    {
        $harbour = DB::table($this->table)
                ->select('harbour_id','harbour_name','show_pic1','show_pic2','show_pic3','city','quote','video_id','introduce','visit','address')
                ->where(['harbour_id'=>$harbour_id])
                ->first();

        if(empty($harbour))
            throw new Exception('港口不存在 ', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);

        $data = [
            'harbour_id'        =>  $harbour->harbour_id,
            'harbour_name'      =>  $harbour->harbour_name,
            'city'              =>  $harbour->city,
            'quote'             =>  $harbour->quote,
            'introduce'         =>   strip_tags($harbour->introduce),
            'video_id'          =>  $harbour->video_id,
            'address'           =>  $harbour->address,
            'img'               =>[
                                    $harbour->show_pic1,
                                    $harbour->show_pic2,
                                    $harbour->show_pic3,
                                ],
            'video_url'         => HostEnum::HOST_NAME.'/Api/video_play?type_id='.HostEnum::VIDEO_TYPE_HARBOUR.'&video_id='.$harbour->video_id
        ];

        return $data;
    }

    /**
     * 港口分布
     * @return array
     * @author alice
     * @date 2016-1-24
     */
    public function GetHarbourList()
    {
        #全部港口
        $harbour_list = DB::table($this->table)
                    ->select('harbour_id','harbour_name','show_pic1')
                    ->orderBy('harbour_id','desc')
                    ->get();

        #热门港口
        $harbour_hot = DB::table($this->table)
            ->select('harbour_id','harbour_name','show_pic1')
            ->orderBy('visit','desc')
            ->take(3)
            ->get();


        $data = [
            'harbour_list'  => $harbour_list,
            'harbour_hot'   => $harbour_hot,
        ];

        return $data;
    }





    /*********************   PC端    *********************/

    /**
     * 港口列表
     * @author alice
     * @date 2016-1-19
     * @return mixed
     */
    public function ShowHarbourList()
    {
        return  DB::table($this->table)->paginate(8);
    }

    /**
     * 港口详情
     * @param $id
     * @author alice
     * @date 2016-1-19
     * @return mixed
     */
    public function ShowHarbourInfo($id)
    {
        return  DB::table($this->table)->where('harbour_id',$id)->first();
    }




}